<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ExportToExcel.aspx.cs" Inherits="Administrator_ExportToExcel" Title="Untitled Page" %>
<%@ Import Namespace="AUSP.Business" %>
<%@ Import Namespace="AUSP.Entities" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" Runat="Server">
<%
    SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["database"]);
    SqlCommand cmd = new SqlCommand("spRegistrationGetList");
    cmd.Connection = cnn;
    cmd.CommandType = System.Data.CommandType.StoredProcedure;
    cmd.Parameters.Add("@OrderBy", SqlDbType.VarChar, 50).Value = RegistrationColumns.Id.ToString();
    cmd.Parameters.Add("@OrderDirection", SqlDbType.VarChar, 50).Value = "ASC";
    cmd.Parameters.Add("@Page", SqlDbType.Int).Value = 0;
    cmd.Parameters.Add("@PageSize", SqlDbType.Int).Value = 0;
    cmd.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output;

    cmd.Connection.Open();
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    adapter.Fill(ds);
    cmd.Connection.Close();

    Page.Response.Clear();
    Page.Response.Charset = "";
    Page.Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", "attachment;Filename=RegistrationList.xls");
    System.IO.StringWriter writer = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
    System.Web.UI.WebControls.DataGrid dg = new DataGrid();
    dg.DataSource = ds.Tables[0];
    dg.DataBind();
    dg.RenderControl(htmlWriter);
    Page.Response.Write(writer.ToString());
    Page.Response.End();

    //RKLib.ExportData.Export objExport = new RKLib.ExportData.Export();
    //objExport.ExportDetails(table, RKLib.ExportData.Export.ExportFormat.CSV, "ListUser.csv");
%>
</asp:Content>

